<html xmlns:tomboy="http://beatniksoftware.com/tomboy" xmlns:link="http://beatniksoftware.com/tomboy/link" xmlns:size="http://beatniksoftware.com/tomboy/size"><head><META http-equiv="Content-Type" content="text/html; charset=utf-8"><title>新便笺 20</title><style type="text/css">
        
	body {  }
	h1 { font-size: xx-large;
     	     font-weight: bold;
     	     border-bottom: 1px solid black; }
	div.note {
		   position: relative;
		   display: block;
		   padding: 5pt;
		   margin: 5pt; 
		   white-space: -moz-pre-wrap; /* Mozilla */
 	      	   white-space: -pre-wrap;     /* Opera 4 - 6 */
 	      	   white-space: -o-pre-wrap;   /* Opera 7 */
 	      	   white-space: pre-wrap;      /* CSS3 */
 	      	   word-wrap: break-word;      /* IE 5.5+ */ }
	</style></head><body><div class="note" id="新便笺 20"><a name="新便笺 20"></a><h1>新便笺 20</h1>
➜  tmp git:(tmp20130719) ✗ git reflog show

➜  tmp git:(tmp20130719) ✗ git branch mytmp d3d4c5e
;white-space:nowrap;text-overflow:ellipsis;overflow:hidden;display:block;width:80%;float:left</div></body></html>




from django.http import HttpResponse
from django.core import serializers
from django.shortcuts import render_to_response
from open_news.models import NewsWebsite, Article
import json

from django.core.serializers.json import Serializer
from django.core.serializers.python import Serializer

class MySerialiser(Serializer):
    # def end_object( self, obj ):
    #     self._current['id'] = obj._get_pk_val()
    #     self.objects.append( self._current )

    def end_object( self, obj):
        self.objects.append( self._current )
    def end_serialization(self):
        for ob in self.objects:
            print ob
            #del ob['pk']
            #del ob['model']
        return super(MySerialiser, self).end_serialization()

    # def end_serialization(self):
    #     self.objects.append( self._current )
    #     return super(MySerialiser, self).end_serialization()


# class JSONSerializer(Serializer):

    # def end_serialization(self):
    #     for ob in self.objects:
    #         del ob['pk']
    #         del ob['model']
    #     # for i, ob in enumerate(self.objects):
    #     #     self.objects[i] = ob.get('fields', {})
    #     return super(JSONSerializer, self).end_serialization()


def Channels(request):
    Channels_list = NewsWebsite.objects.all()
    # s = JSONSerializer()
    # s.serialize(Channels_list)
    #print dir(Channels_list)
    # for item in Channels_list:
    #     print item

    # for ob in Channels_list.objects:
    #     del ob['pk']
    #     del ob['model']
    serializer = MySerialiser()
    # serializer = Serializer()
    data = serializer.serialize(Channels_list, fields=('name', 'url'), formats=['jsonp', 'json'])

    # s=serializers.serialize('json', Channels_list,use_natural_keys=True)
    custom_response = HttpResponse(json.dumps(data), mimetype='text/json')
    # custom_response["Access-Control-Allow-Origin"] = "*"
    # custom_response["Access-Control-Allow-Methods"] = "POST, GET, OPTIONS"
    # custom_response["Access-Control-Allow-Headers"] = "Content-Type"
    # custom_response["Access-Control-Allow-Credentials"] = "true"
    

    return custom_response




def NewsByChannel(request, channel):
    article_list = Article.objects.filter(news_website__name=channel)
    articles = serializers.serialize('json', article_list,  fields=('title', 'url', 'content'))
    
    custom_response =HttpResponse(articles, mimetype='application/json')

    return custom_response